package com.sc.syllabus.money;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sc.syllabus.R;
import com.srain.utils.StringUtils;

import java.util.List;

/**
 * Created by liushuanglong on 2017/9/12.
 */

public class MoneyAdapter extends BaseAdapter {

    private Context mContext;
    private List<MoneyInfo> data;
    private LayoutInflater mInflater;

    public MoneyAdapter(Context context, List<MoneyInfo> data) {
        mContext = context;
        this.data = data;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return ((null != data) ? data.size() : 0);
    }

    @Override
    public MoneyInfo getItem(int position) {
        MoneyInfo bean = null;
        if (null != data) {
            bean = data.get(position);
        }
        return bean;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (null == convertView) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_money, null);
            holder.txtTitle = (TextView) convertView.findViewById(R.id.text_title);
            holder.txtAmount = (TextView) convertView.findViewById(R.id.text_amount);
            holder.txtStart = (TextView) convertView.findViewById(R.id.text_startAt);
            holder.txtEnd = (TextView) convertView.findViewById(R.id.text_endAt);
            holder.txtLl = (TextView) convertView.findViewById(R.id.text_ll);
            holder.txtType = (TextView) convertView.findViewById(R.id.text_type);
            holder.txtContent = (TextView) convertView.findViewById(R.id.text_content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (null != data) {
            MoneyInfo bean = data.get(position);
            String start = "借款时间 : " + StringUtils.numericToStr(String.valueOf(bean.getDate_jk()));
            String end = "还款时间 : " + StringUtils.numericToStr(String.valueOf(bean.getDate_yqhk()));
            String type = "类  型 : " + ((0 == bean.getType()) ? "借入" : "借出");
            String content = "内  容 : " + bean.getContent();
            holder.txtTitle.setText(bean.getTitle());
            holder.txtAmount.setText("金  额 : " + bean.getAmount() + "");
            holder.txtLl.setText("利  率 : " + bean.getInterest() + "");
            holder.txtStart.setText(start);
            holder.txtEnd.setText(end);
            holder.txtType.setText(type);
            holder.txtContent.setText(content);
        }
        return convertView;
    }

    private class ViewHolder {
        TextView txtTitle;
        TextView txtStart;
        TextView txtEnd;
        TextView txtAmount;
        TextView txtLl;
        TextView txtType;
        TextView txtContent;
    }
}
